package com.bookm.bookm.entity;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.bookm.bookm.enums.ResultCode;

/**
 * 结果集实体类
 */
public class Result {
    /*
        业务代码
     */
    private Integer code;
    /*
        消息
     */
    private String msg;
    /*
        返回的数据
     */
    private Object data;

    public Result() {
    }

    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 根据状态码枚举设置状态码和状态信息的值
     * @param code 状态码枚举
     */
    public void setResultCode(ResultCode code) {
        this.code = code.getCode();
        this.msg = code.getMessage();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return JSONUtil.toJsonStr(this);
    }
}
